vtd: Fix init/destroy domain hooks.
authorKeir Fraser <keir@xensource.com>
Thu, 20 Sep 2007 14:59:51 +0000 (15:59 +0100)
committerKeir Fraser <keir@xensource.com>
Thu, 20 Sep 2007 14:59:51 +0000 (15:59 +0100)
Signed-off-by: Keir Fraser <keir@xensource.com>
xen/arch/x86/domain.c
xen/arch/x86/hvm/hvm.c
xen/arch/x86/hvm/vmx/vtd/intel-iommu.c
xen/arch/x86/hvm/vmx/vtd/io.c
xen/include/asm-x86/iommu.h

index 2080e70961f0ca966b239a628a670ed84479e57f..dafee075f9f2a9fab8da04e6f5d6ff2782742ec8 100644 (file)
@@ -44,6 +44,7 @@
 #include <asm/hvm/support.h>
 #include <asm/msr.h>
 #include <asm/nmi.h>
+#include <asm/iommu.h>
 #ifdef CONFIG_COMPAT
 #include <compat/vcpu.h>
 #endif
@@ -505,10 +506,16 @@ int arch_domain_create(struct domain *d)
             virt_to_page(d->shared_info), d, XENSHARE_writable);
     }
 
+    if ( (rc = iommu_domain_init(d)) != 0 )
+        goto fail;
+
     if ( is_hvm_domain(d) )
     {
         if ( (rc = hvm_domain_initialise(d)) != 0 )
+        {
+            iommu_domain_destroy(d);
             goto fail;
+        }
     }
     else
     {
@@ -538,6 +545,8 @@ void arch_domain_destroy(struct domain *d)
     if ( is_hvm_domain(d) )
         hvm_domain_destroy(d);
 
+    iommu_domain_destroy(d);
+
     paging_final_teardown(d);
 
     free_xenheap_pages(
index da0bc8fcdcfec659877a1379db1107c6ef2e50b2..b465a03b801f45d034f82b67b5e4f2b711797bd6 100644 (file)
@@ -48,7 +48,6 @@
 #include <public/hvm/ioreq.h>
 #include <public/version.h>
 #include <public/memory.h>
-#include <asm/iommu.h>
 
 int hvm_enabled __read_mostly;
 
@@ -220,21 +219,13 @@ int hvm_domain_initialise(struct domain *d)
     if ( rc != 0 )
         return rc;
 
-    rc = iommu_domain_init(d);
-    if ( rc != 0 )
-        return rc;
-
     vpic_init(d);
     vioapic_init(d);
 
     hvm_init_ioreq_page(d, &d->arch.hvm_domain.ioreq);
     hvm_init_ioreq_page(d, &d->arch.hvm_domain.buf_ioreq);
 
-    rc = hvm_funcs.domain_initialise(d);
-    if ( rc != 0 )
-        release_devices(d);
-
-    return rc;
+    return hvm_funcs.domain_initialise(d);
 }
 
 void hvm_domain_relinquish_resources(struct domain *d)
@@ -250,7 +241,6 @@ void hvm_domain_relinquish_resources(struct domain *d)
 
 void hvm_domain_destroy(struct domain *d)
 {
-    release_devices(d);
     hvm_funcs.domain_destroy(d);
 }
 
index 927c68064b048f354644afd8b5e0ec8ae5b41b18..f1f77fcb08a9c832f66ec8cdc287ee842ae56e46 100644 (file)
@@ -972,7 +972,7 @@ int iommu_domain_init(struct domain *domain)
         gdprintk(XENLOG_ERR VTDPREFIX,
                  "IOMMU: hardware doesn't support the agaw\n");
         agaw = find_next_bit(&sagaw, 5, agaw);
-        if (agaw >= 5)
+        if ( agaw >= 5 )
             return -ENODEV;
     }
     hd->agaw = agaw;
index 48b08136886ba23c5edcb6a6b422f70ee9374374..89f0a9036377118363e243b52b399d6f56c146b1 100644 (file)
@@ -134,19 +134,17 @@ void hvm_dpci_eoi(unsigned int guest_gsi, union vioapic_redir_entry *ent)
     }
 }
 
-int release_devices(struct domain *d)
+void iommu_domain_destroy(struct domain *d)
 {
     struct hvm_domain *hd = &d->arch.hvm_domain;
     uint32_t i;
-    int ret = 0;
 
     if ( !vtd_enabled )
-        return ret;
+        return;
 
     for ( i = 0; i < NR_IRQS; i++ )
         if ( hd->irq.mirq[i].valid )
-            ret = pirq_guest_unbind(d, i);
+            pirq_guest_unbind(d, i);
 
     iommu_domain_teardown(d);
-    return ret;
 }
index cc19d840fd33e8894337c35f4879bc3814f077c8..914145c503a4cd5c9b6911555e49b2ea4f941408 100644 (file)
@@ -68,8 +68,8 @@ struct iommu {
 
 int iommu_setup(void);
 int iommu_domain_init(struct domain *d);
+void iommu_domain_destroy(struct domain *d);
 int assign_device(struct domain *d, u8 bus, u8 devfn);
-int release_devices(struct domain *d);
 int iommu_map_page(struct domain *d, dma_addr_t gfn, dma_addr_t mfn);
 int iommu_unmap_page(struct domain *d, dma_addr_t gfn);
 void iommu_flush(struct domain *d, dma_addr_t gfn, u64 *p2m_entry);